﻿using System.Security.Permissions;
using System.Windows.Forms;
using System;

namespace Evaluant.PS4VS
{
    /// <summary>
    /// Summary description for MyControl.
    /// </summary>
    public partial class MyControl : UserControl
    {
        public MyControl()
        {
            InitializeComponent();
            console.SizeChanged += new EventHandler(console_SizeChanged);
        }

        void console_SizeChanged(object sender, EventArgs e)
        {
            vScrollBar1.Maximum = console.AutoScrollOffset.Y;
        }

        public ConsoleControl Console
        {
            get { return console; }
        }

        /// <summary> 
        /// Let this control process the mnemonics.
        /// </summary>
        [UIPermission(SecurityAction.LinkDemand, Window = UIPermissionWindow.AllWindows)]
        protected override bool ProcessDialogChar(char charCode)
        {
            // If we're the top-level form or control, we need to do the mnemonic handling
            if (charCode != ' ' && ProcessMnemonic(charCode))
            {
                return true;
            }
            return base.ProcessDialogChar(charCode);
        }

        /// <summary>
        /// Enable the IME status handling for this control.
        /// </summary>
        protected override bool CanEnableIme
        {
            get
            {
                return true;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1300:SpecifyMessageBoxOptions")]
        private void button1_Click(object sender, System.EventArgs e)
        {
            MessageBox.Show(this,
                            string.Format(System.Globalization.CultureInfo.CurrentUICulture, "We are inside {0}.button1_Click()", this.ToString()),
                            "Powershell outpout");
        }

        internal string ReadLine()
        {
            throw new NotImplementedException();
        }

        internal void Write(System.Drawing.Color color, System.Drawing.Color color_2, string value)
        {
            throw new System.NotImplementedException();
        }

        internal void WriteLine(System.Drawing.Color color, System.Drawing.Color color_2, string message)
        {
            throw new System.NotImplementedException();
        }

        public void RefreshScroll()
        {
            vScrollBar1.Visible = console.CurrentLine > 0;
            vScrollBar1.Maximum = console.CurrentLine;
            vScrollBar1.Minimum = 0;
        }

        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            RefreshScroll();
        }

        private void ScrollConsole(object sender, ScrollEventArgs e)
        {
            //if (e.NewValue > 0)
            console.AutoScrollOffset = new System.Drawing.Point(0, -e.NewValue);
            Refresh();
        }
    }
}
